package com.kws.commercial.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kws.commercial.dao.CommercialFileManagement;
import com.kws.commercial.dao.Info.QueryFileManagementInfo;
import com.kws.commercial.dao.Rq.CreateFileManagementRq;
import com.kws.commercial.dao.Rq.QueryFileManagementPageRq;
import com.kws.commercial.dao.Rq.QueryFileRq;
import com.kws.commercial.mapper.CommercialFileManagementMapper;
import com.kws.commercial.service.CommercialFileManagementService;
import com.kws.common.core.enums.ModelOpType;
import com.kws.common.core.sys.Ksys;
import com.kws.common.core.utils.KConstants;
import com.kws.common.core.utils.bean.BeanUtils;
import com.kws.common.security.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>CommercialFileManagementServiceImpl</b>
 *
 * @description: CommercialFileManagementServiceImpl <br>
 * @date: 2024/10/29 10:33 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class CommercialFileManagementServiceImpl extends ServiceImpl<CommercialFileManagementMapper, CommercialFileManagement> implements CommercialFileManagementService {
    private static final Logger logger = LoggerFactory.getLogger(CommercialFileManagementServiceImpl.class);


    @Override
    public PageInfo<QueryFileManagementInfo> queryFileManagementPage(QueryFileManagementPageRq rq) {
        PageHelper.startPage(rq.getPageNum(),rq.getPageSize());
        Long companyId = SecurityUtils.getCompanyId();
        QueryFileRq queryFileRq = new QueryFileRq();
        queryFileRq.setFileName(rq.getFileName());
        queryFileRq.setCompanyId(companyId);
        queryFileRq.setSchemeName(rq.getSchemeName());
        queryFileRq.setStartDate(rq.getStartDate());
        queryFileRq.setEndDate(rq.getEndDate());
        List<QueryFileManagementInfo> list = baseMapper.queryFileManagementPage(queryFileRq);
        return new PageInfo<QueryFileManagementInfo>(list);
    }

    @Override
    public boolean createFileManagement(CreateFileManagementRq rq) {
        CommercialFileManagement commercialFileManagement = new CommercialFileManagement();
        BeanUtils.copyProperties(rq,commercialFileManagement);
        commercialFileManagement.setCompanyId(SecurityUtils.getCompanyId());
        Ksys.setBasicModelData(commercialFileManagement,SecurityUtils.getStringUserId(), KConstants.DATA_ENABLE, ModelOpType.CREATE);
        int insert = baseMapper.insert(commercialFileManagement);
        if (1 == insert){
            return true;
        }
        return false;
    }

    @Override
    public QueryFileManagementInfo queryFileManagementById(Long id) {
        return baseMapper.queryFileManagementById(id);
    }

    @Override
    public boolean deleteFileManagementById(Long id) {
        CommercialFileManagement commercialFileManagement = baseMapper.selectById(id);
        commercialFileManagement.setEnable("0");
        Ksys.setBasicModelData(commercialFileManagement,SecurityUtils.getStringUserId(),KConstants.DATA_DISABLE,ModelOpType.UPDATE);
        int i = baseMapper.updateById(commercialFileManagement);
        if (1 == i){
            return true;
        }
        return false;
    }
}
